<template>
  <div class="upload">
    <h2>图片上传</h2>
    <el-upload
      action="/resource/users/upload"
      list-type="picture-card"
      :auto-upload="true"
      :limit="5"
      :data="{ _id }"
      :on-success="suc"
      drag
      multiple
    >
      <i slot="default" class="el-icon-plus"></i>
      <div slot="file" slot-scope="{ file }">
        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
        <span class="el-upload-list__item-actions">
          <span
            class="el-upload-list__item-preview"
            @click="handlePictureCardPreview(file)"
          >
            <i class="el-icon-zoom-in"></i>
          </span>
          <span
            v-if="!disabled"
            class="el-upload-list__item-delete"
            @click="handleDownload(file)"
          >
            <i class="el-icon-download"></i>
          </span>
          <span
            v-if="!disabled"
            class="el-upload-list__item-delete"
            @click="handleRemove(file)"
          >
            <i class="el-icon-delete"></i>
          </span>
        </span>
      </div>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>
  </div>
</template>

<script>
import config from "../../utils/config.js";
export default {
  name: "user-img",
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      _id: "",
      url: config["resource"] + "/",
    };
  },
  created() {
    this._id = this.$route.params._id;
  },
  methods: {
    handleRemove(file) {
      console.log(1);
      console.log(file);
    },
    handlePictureCardPreview(file) {
      console.log(111);
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload(file) {
      console.log(222);
      console.log(file);
    },
    suc(response, file, fileList) {
      console.log(response, file, fileList);
      this.$message({
        message: "上传成功",
        type: "success",
      });
      this.$router.replace("/user/list");
    },
  },
};
</script>

<style lang="scss" scoped>
.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.upload {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>